<template>
    <div>
        <div class="products_block ">
            <div class="nav_position">
                <span class="icon_home"></span>您的位置：
                <div class="position_detail">
                    <nuxt-link to="/">首页</nuxt-link>
                    <span class="el-icon-arrow-right"></span>
                    <nuxt-link :to="firstMenu.url">{{ firstMenu.title }}</nuxt-link>
                    <span class="el-icon-arrow-right" v-if="secondMenu.title"></span>
                    <span v-if="secondMenu.title">{{ secondMenu.title }}</span>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import menuData from "@/plugins/menu-nav-data";
import managerMenuData from "@/plugins/manager-nav-data";
import { getUser } from "@/utils/auth";
export default {
    data() {
        return {
            menuData: [],
            firstMenu: {
                url: "",
                title: ""
            },
            secondMenu: {
                title: ""
            }
        };
    },
    methods: {
        activeMenu: function () {
            // 循环1级
            this.menuData.forEach(item => {

                if (item.url == this.$route.path) {
                    this.firstMenu.title = item.title;
                    this.firstMenu.url = item.url;
                    return;
                }
                // 循环2级
                item.childs.forEach(itemChild => {

                    // 循环3级
                    itemChild.childs.forEach(grandsonChild => {

                        if (grandsonChild.url == this.$route.path || this.$route.path.indexOf(grandsonChild.url)) {

                            this.firstMenu.title = item.title;
                            this.firstMenu.url = item.url;

                            this.secondMenu.title = itemChild.title;
                            // this.secondMenu.url = grandsonChild.url;
                            return;
                        }
                    })
                })
            })
        }
    },
    mounted: function () {
        this.menuData = JSON.parse(JSON.stringify(menuData));
        if (getUser().type == 1) {
            this.menuData = JSON.parse(JSON.stringify(managerMenuData));
        }
        this.activeMenu();
    }
}
</script>